import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/Login.vue'
import Home from '../components/Home.vue'
import Welcome from '../components/Welcome.vue'
import Users from '../components/users/Users.vue'
import Rights from '../components/auth/Rights.vue'
import Roles from '../components/auth/Roles.vue'
import Goods from '../components/goods/Goods.vue'
import Categories from '../components/goods/Categories.vue'
import Params from '../components/goods/Params.vue'
import Orders from '../components/orders/Orders.vue'
import Reports from '../components/reports/Reports.vue'

Vue.use(VueRouter)

const routes = [
  {path:'/',redirect:'/login'},//路由重定向
  {path:'/login',component:Login},
  {path:'/home',
  component:Home,
  redirect:'/welcome',
  children:[
    {path:'/welcome',component:Welcome},
    {path:'/users',component:Users},
    {path:'/roles',component:Roles},
    {path:'/rights',component:Rights},
    {path:'/goods',component:Goods},
    {path:'/categories',component:Categories},
    {path:'/params',component:Params},
    {path:'/orders',component:Orders},
    {path:'/reports',component:Reports},
  ]}
]

const router = new VueRouter({
  routes
})

//路由守卫 to 去哪里 from从哪来 next放行
// router.beforeEach((to,from,next)=>{
//   if(to.path=='/login') return next();
//   const tk=sessionStorage.getItem('token');
//   if(!tk) return next('/login');
//   next();//放行
// })

export default router
